package com.eazyrpc.bigdata.sql;

import com.eazyrpc.thrift.base.SQLService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;



public class RPCServer {

    Logger logger =  LogManager.getLogger();
    public void startServer(){
        try {
            logger.error("look up `${MAVEN_HOME}`");
            System.out.println("FastArrow Server start ... ");
            TServerSocket serverTransport = new TServerSocket(9090);
            TServer.Args tArgs = new TServer.Args(serverTransport);
            TProcessor tProcessor = new SQLService.Processor<SQLService.Iface>(new SQLServiceImpl());
            tArgs.processor(tProcessor);
            tArgs.protocolFactory(new TBinaryProtocol.Factory());
//            tArgs.protocolFactory(new TCompactProtocol.Factory());
//            tArgs.protocolFactory(new TJSONProtocol.Factory());
            TServer server = new TSimpleServer(tArgs);
            server.serve();
        } catch (TTransportException e) {
            e.printStackTrace();
        }
    }
}
